home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCX_LIB.ARJ / RD_DEMO.C < prev    next >
C/C++ Source or Header  |  1991-04-03  |  6KB  |  170 lines

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *  RD_DEMO.C - PCX_LIB PCX Image File Read Demonstration Program
  5.  *
  6.  *  Version:    1.00B
  7.  *
  8.  *  History:    91/02/14 - Created
  9.  *              91/04/01 - Release 1.00A
  10.  *              91/04/06 - Release 1.00B
  11.  *
  12.  *  Compiler:   Microsoft C V6.0
  13.  *
  14.  *  Author:     Ian Ashdown, P.Eng.
  15.  *              byHeart Software
  16.  *              620 Ballantree Road
  17.  *              West Vancouver, B.C.
  18.  *              Canada V7S 1W3
  19.  *              Tel. (604) 922-6148
  20.  *              Fax. (604) 987-7621
  21.  *
  22.  *  Copyright:  Public Domain
  23.  *
  24.  *************************************************************************
  25.  */
  26.  
  27. /*      INCLUDE FILES                                                   */
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <conio.h>
  32. #include <graph.h>
  33. #include "pcx_ext.h"
  34.  
  35. /*      FORWARD REFERENCES                                              */
  36.  
  37. /*      GLOBALS                                                         */
  38.  
  39. static char *use_msg[] =        /* Program usage message                */
  40. {
  41.   "  Synopsis:  This public domain program displays a Paintbrush (R) PCX",
  42.   "-format\n             image file.\n\n  Usage:     RD_DEMO filename vi",
  43.   "deo_mode\n\n             where \"filename\" is the name of a PCX-form",
  44.   "at image file and\n             \"video_mode\" is an MS-DOS video mod",
  45.   "e.  Valid values are:\n\n                4   - 320 x 200 4-color CGA",
  46.   "\n                5   - 320 x 200 4-color CGA (color burst off)\n    ",
  47.   "            6   - 640 x 200 2-color CGA\n               13   - 320 x ",
  48.   "200 16-color EGA/VGA\n               14   - 640 x 200 16-color EGA/VG",
  49.   "A\n               15   - 640 x 350 2-color EGA/VGA\n               16",
  50.   "   - 640 x 350 16-color EGA/VGA\n               17   - 640 x 480 2-co",
  51.   "lor VGA\n               18   - 640 x 480 16-color VGA\n              ",
  52.   " 19   - 320 x 200 256-color VGA\n\n             The file must be comp",
  53.   "atible with the indicated video mode.\n",
  54.   (unsigned char *) NULL
  55. };
  56.  
  57. /*      PUBLIC FUNCTIONS                                                */
  58.  
  59. /*
  60.  *************************************************************************
  61.  *
  62.  *  MAIN - Executive Function
  63.  *
  64.  *  Purpose:    To read and display a PCX-format image file.
  65.  *
  66.  *  Setup:      int main
  67.  *              (
  68.  *                int argc,
  69.  *                char **argv
  70.  *              )
  71.  *
  72.  *  Where:      argc is the number of command-line arguments.
  73.  *              argv is a pointer to an array of command-line argument
  74.  *                strings.
  75.  *
  76.  *  Return:     0 if successful; otherwise 2.
  77.  *
  78.  *  Note:       Usage is:
  79.  *
  80.  *                RD_DEMO filename video_mode
  81.  *
  82.  *              where:
  83.  *
  84.  *                filename is the name of a PCX-format image file.
  85.  *                video_mode is the MS-DOS video mode.  Valid values are:
  86.  *
  87.  *                    4 -        320 x 200 4-color CGA
  88.  *                    5 -        320 x 200 4-color CGA (color burst off)
  89.  *                    6 -        640 x 200 2-color CGA
  90.  *                   13 -        320 x 200 16-color EGA/VGA
  91.  *                   14 -        640 x 200 16-color EGA/VGA
  92.  *                   15 -        640 x 350 2-color EGA/VGA
  93.  *                   16 -        640 x 350 16-color EGA/VGA
  94.  *                   17 -        640 x 480 2-color VGA
  95.  *                   18 -        640 x 480 16-color VGA
  96.  *                   19 -        320 x 200 256-color VGA
  97.  *
  98.  *************************************************************************
  99.  */
  100.  
  101. int main
  102. (
  103.   int argc,
  104.   char **argv
  105. )
  106. {
  107.   int i;                /* Scratch counter                              */
  108.   int vmode;            /* Video mode                                   */
  109.   BOOL status = FALSE;  /* Return status                                */
  110.  
  111.   /* Display program title                                              */
  112.  
  113.   puts("\nRD_DEMO - PCX Image File Display Demonstration Program\n");
  114.  
  115.   if (argc == 3)        /* Check for filename and video mode parameters */
  116.   {
  117.     vmode = atoi(argv[2]);      /* Get the video mode                   */
  118.  
  119.     /* Validate the video mode (must be valid MS-DOS graphics mode)     */
  120.  
  121.     if ((vmode >= 4 && vmode <= 6) || (vmode >= 13 && vmode <= 19))
  122.       status = TRUE;
  123.   }
  124.  
  125.   if (status == TRUE)
  126.   {
  127.     if (_setvideomode(vmode) == 0)      /* Set the video mode           */
  128.     {
  129.       /* Report error                                                   */
  130.  
  131.       fprintf(stderr,
  132.           "ERROR: could not set display adapter to mode %d.\n", vmode);
  133.  
  134.       return (2);
  135.     }
  136.  
  137.     /* Read and display the file (assume video page zero)               */
  138.  
  139.     if ((status = pcx_read(argv[1], vmode, 0)) == TRUE)
  140.     {
  141.       while (!kbhit())  /* Wait for a keystroke                         */
  142.         ;
  143.  
  144.       (void) getch();   /* Clear the keyboard buffer                    */
  145.     }
  146.  
  147.     (void) _setvideomode(_DEFAULTMODE);         /* Reset the video mode */
  148.  
  149.     if (status == FALSE)
  150.     {
  151.       /* Report error                                                   */
  152.  
  153.       fprintf(stderr, "\nRD_DEMO - PCX Image File Display Demonstration");
  154.       fprintf(stderr, " Program\n\nERROR: Could not read file %s.\n",
  155.           argv[1]);
  156.     }
  157.   }
  158.   else          /* Display usage information                            */
  159.   {
  160.     while (use_msg[i] != (unsigned char *) NULL)
  161.       fputs(use_msg[i++], stderr);
  162.   }
  163.  
  164.   if (status == TRUE)
  165.     return (0);
  166.   else
  167.     return (2);
  168. }
  169.  
  170.